import axios from 'axios';
import {Loading,Message} from 'element-ui';

let base = '/api';
let loadingInstance;

export default axios;

axios.defaults.timeout = 6000;
var instance = axios.create({
	headers: {'content-type': 'application/json',
		'X-Auth-Token': (sessionStorage.getItem('Auth') != null && sessionStorage.getItem('Auth') != undefined)?sessionStorage.getItem('Auth'):''
	}
});

instance.interceptors.response.use(
	response => {
		if(response.data.code == 0 && response.data.message == '成功' ) {
			return response;
		} else {
			if(response.data.result == 0) {
				return response;
			} else {
				Message({
					message: response.data.message ? response.data.message : '服务器异常',
					type: 'error',
					showClose: true
				})
			}
		}
	},
	error => {
		return Promise.reject(error)
	});


/*公用接口开始*/
export const requestLogin = params => { return instance.post(`${base}/login.do`, params).then(res => res.data); };

export const getAreaList = params => { return instance.post(`${base}/common/arealist`, params).then(res => res.data); };
export const getSysConfig = params => { return instance.post(`${base}/common/getConfig`, params).then(res => res.data); };
/*公用接口开始*/

/*管理员接口开始*/
export const getShopList = params => { return instance.post(`${base}/goods/getShopList`, params).then(res => res.data); };
export const getRoleList = params => { return instance.post(`${base}/role/list`, params).then(res => res.data); };

export const addRole = params => { return instance.post(`${base}/role/add`, params).then(res => res.data); }

export const editRole = params => { return instance.post(`${base}/role/update`, params).then(res => res.data); }

export const removeRole = params => { return instance.post(`${base}/role/delete`, params).then(res => res.data); }

export const getPositionList = params => { return instance.post(`${base}/position/list`, params).then(res => res.data); };

export const addPosition = params => { return instance.post(`${base}/position/add`, params).then(res => res.data); }

export const editPosition = params => { return instance.post(`${base}/position/update`, params).then(res => res.data); }

export const removePosition = params => { return instance.post(`${base}/position/delete`, params).then(res => res.data); }

export const getSysUserList = params => { return instance.post(`${base}/sysuser/queryUserList`, params).then(res => res.data); };

export const editSysUser = params => { return instance.post(`${base}/sysuser/updateSysUser`, params).then(res => res.data); }

export const addSysUser = params => { return instance.post(`${base}/sysuser/add`, params).then(res => res.data); }

export const removeSysUser = params => { return instance.post(`${base}/sysuser/delete`, params).then(res => res.data); }
/*管理员接口结束*/

/*用户接口开始*/
export const getUserList = params => { return instance.post(`${base}/user/list`, params).then(res => res.data); }

export const removeUser = params => { return instance.post(`${base}/user/remove`, params).then(res => res.data); }

export const editUser = params => { return instance.post(`${base}/user/updateInfo`, params).then(res => res.data); }

export const addUser = params => { return instance.post(`${base}/user/add`, params).then(res => res.data); }

export const getBalanceList = params => { return instance.post(`${base}/user/balancelist`, params).then(res => res.data); }

export const getUserLevelList = params => { return instance.post(`${base}/user/levelLists`, params).then(res => res.data); }

export const getUpAndDownLevel = params => { return instance.post(`${base}/user/getUpAndDownLevel`, params).then(res => res.data); }

export const getLevel = params => { return instance.post(`${base}/user/level`, params).then(res => res.data); }

export const getUserInfo = params => { return instance.post(`${base}/user/info`, params).then(res => res.data); }

export const getUpdateLevel = params => { return instance.post(`${base}/user/updateLevels`, params).then(res => res.data); }

export const getSonLevel = params => { return instance.post(`${base}/user/sonList`, params).then(res => res.data); }

export const getParentLevel = params => { return instance.post(`${base}/user/parentList`, params).then(res => res.data); }
export const updateParentLevel = params => { return instance.post(`${base}/user/editParentUser`, params).then(res => res.data); }
export const addParentLevel = params => { return instance.post(`${base}/user/addParentUser`, params).then(res => res.data); }

export const updateSafeCode = params => { return instance.post(`${base}/user/updateSafeCode`, params).then(res => res.data); }

/*用户接口结束*/

/*商铺接口开始*/
export const getSelfShopList = params => { return instance.post(`${base}/shop/selfShopList`, params).then(res => res.data); }

export const addSelfShop = params => { return instance.post(`${base}/shop/addSelfShop`, params).then(res => res.data); }

export const updateSelfShop = params => { return instance.post(`${base}/shop/updateSelfShop`, params).then(res => res.data); }

export const closeSelfShop = params => { return instance.post(`${base}/shop/closeSelfShop`, params).then(res => res.data); }

export const shopTypeList = params => { return instance.post(`${base}/shop/shopTypeList`, params).then(res => res.data); }

export const addShopType = params => { return instance.post(`${base}/shop/addShopType`, params).then(res => res.data); }

export const deleteShopType = params => { return instance.post(`${base}/shop/deleteShopType`, params).then(res => res.data); }

export const updateShopType = params => { return instance.post(`${base}/shop/updateShopType`, params).then(res => res.data); }

export const getEnterShopList = params => { return instance.post(`${base}/shop/enterShopList`, params).then(res => res.data); }

export const updateEnterShop = params => { return instance.post(`${base}/shop/updateEnterShop`, params).then(res => res.data); }

export const closeEnterShop = params => { return instance.post(`${base}/shop/closeEnterShop`, params).then(res => res.data); }

export const checkEnterShop = params => { return instance.post(`${base}/shop/checkEnterShop`, params).then(res => res.data); }

export const viewEnterShopRejectedReason = params => { return instance.post(`${base}/shop/viewEnterShopRejectedReason`, params).then(res => res.data); }
/*商铺接口结束*/

/*商品接口开始*/
export const brandList = params => { return instance.post(`${base}/goods/brandList`, params).then(res => res.data); }
export const goodsInfo = params => { return instance.post(`${base}/goods/info`, params).then(res => res.data); }
export const deleteGoods = params => { return instance.post(`${base}/goods/delete`, params).then(res => res.data); }
export const updateProduct = params => { return instance.post(`${base}/goods/updateProduct`, params).then(res => res.data); }




export const addGoodsBrand = params => { return instance.post(`${base}/goods/addGoodsBrand`, params).then(res => res.data); }

export const editGoodsBrand = params => { return instance.post(`${base}/goods/editGoodsBrand`, params).then(res => res.data); }

export const categoryList = params => { return instance.post(`${base}/goods/categoryList`, params).then(res => res.data); }

export const deleteGoodsBrand = params => { return instance.post(`${base}/goods/deleteGoodsBrand`, params).then(res => res.data); }

export const addGoodsCategory = params => { return instance.post(`${base}/goods/addGoodsCategory2`, params).then(res => res.data); }

export const editGoodsCategory = params => { return instance.post(`${base}/goods/updateGoodsCategory`, params).then(res => res.data); }

export const deleteGoodsCategory = params => { return instance.post(`${base}/goods/deleteGoodsCategory`, params).then(res => res.data); }

export const categoryFeatureList = params => { return instance.post(`${base}/goods/categoryFeatureList`, params).then(res => res.data); }

export const addGoodsCategoryFeature = params => { return instance.post(`${base}/goods/addGoodsCategoryFeature`, params).then(res => res.data); }

export const deleteGoodsCategoryFeature = params => { return instance.post(`${base}/goods/deleteGoodsCategoryFeature`, params).then(res => res.data); }

export const categoryFeatureValueList = params => { return instance.post(`${base}/goods/categoryFeatureValueList`, params).then(res => res.data); }

export const addCategoryFeatureValue = params => { return instance.post(`${base}/goods/addCategoryFeatureValue`, params).then(res => res.data); }

export const deleteCategoryFeatureValue = params => { return instance.post(`${base}/goods/deleteCategoryFeatureValue`, params).then(res => res.data); }

export const getGoodsList = params => { return instance.post(`${base}/goods/list`, params).then(res => res.data); }

export const checkGoods = params => { return instance.post(`${base}/goods/checkGoods`, params).then(res => res.data); }

export const enableCheckGoods = params => { return instance.post(`${base}/goods/enableCheckGoods`, params).then(res => res.data); }

export const enableCheckGoods2 = params => { return instance.post(`${base}/goods/enableCheckGoods2`, params).then(res => res.data); }

export const openGoods = params => { return instance.post(`${base}/goods/openGoods`, params).then(res => res.data); }

export const closeGoods = params => { return instance.post(`${base}/goods/closeGoods`, params).then(res => res.data); }

export const viewGoodsRejectedReason = params => { return instance.post(`${base}/goods/viewGoodsRejectedReason`, params).then(res => res.data); }

export const goodsCategoryList = params => { return instance.post(`${base}/goods/goodsCategoryList`, params).then(res => res.data); }
export const goodsAdd = params => { return instance.post(`${base}/goods/add`, params).then(res => res.data); }
export const goodsUpdate = params => { return instance.post(`${base}/goods/update`, params).then(res => res.data); }

export const getAllGoodsCategory = params => { return instance.post(`${base}/goods/getAllGoodsCategory`, params).then(res => res.data); }
export const getAllGoodsCategory2 = params => { return instance.post(`${base}/goods/getAllGoodsCategory2`, params).then(res => res.data); }
export const getAllCategoryFeatureList = params => { return instance.post(`${base}/goods/getAllCategoryFeatureList`, params).then(res => res.data); }

export const goodsSkuList = params => { return instance.post(`${base}/goods/getSkuList`, params).then(res => res.data); }


// 商品规格
export const getFirstCategory = params => { return instance.post(`${base}/goods/getFirstCategory`, params).then(res => res.data); }

/*商品接口结束*/


/*活动相应接口****开始 */
export const activityList = params => { return instance.post(`${base}/activity/activityList`, params).then(res => res.data);}
export const refund = params => { return instance.get(`${base}/activity/activityRefund`, { params: params }) }
export const addActivity = params => { return instance.post(`${base}/activity/addActivity`, params).then(res => res.data); }

export const updateActivity = params => { return instance.post(`${base}/activity/updateActivity`, params).then(res => res.data); }

export const getActivity = params => { return instance.get(`${base}/activity/getActivity`, { params: params }); }

export const deleteActivity = params => { return instance.get(`${base}/activity/deleteActivity`, { params: params }); }

export const getActivityAndEnroll = params => { return instance.get(`${base}/activity/getActivityAndEnroll`, { params: params }); }

export const getActivityAndEnrollMore = params => { return instance.get(`${base}/activity/getActivityAndEnrollMore`, { params: params }); }

//活动分类--
export const getActivityClassify = params => { return instance.post(`${base}/activity/activityCategory`, params).then(res => res.data);}

export const addActivityClassify = params => { return instance.post(`${base}/activity/addCategory`, params).then(res => res.data);}
export const updateActivityClassify = params => { return instance.post(`${base}/activity/updateCategory`, params).then(res => res.data);}
export const delateActivityClassify = params => { return instance.post(`${base}/activity/deleteCategory`, params).then(res => res.data);}
/*活动相应接口****结束*/

/*邀请有礼接口*/
export const transactionList = params => { return instance.post(`${base}/transaction/transactionList`, params).then(res => res.data);}
export const getInviteConfig = params => { return instance.post(`${base}/transaction/getInviteConfig`, params).then(res => res.data);}
export const modifyInviteConfig = params => { return instance.post(`${base}/transaction/modifyInviteConfig`, params).then(res => res.data);}




/* gmc */
export const queryLog = params => { return instance.post(`${base}/log/queryLog`, params).then(res => res.data); };

export const queryNews = params => { return instance.post(`${base}/news/queryNews`, params).then(res => res.data); };

export const addNews = params => { return instance.post(`${base}/news/addNews`, params).then(res => res.data); }

export const editNews = params => { return instance.post(`${base}/news/editNews`, params).then(res => res.data); }

export const deleteNews = params => { return instance.post(`${base}/news/deleteNews`, params).then(res => res.data)}

export const newsQueryTags = params => { return instance.post(`${base}/news/queryTags`, params ).then(res => res.data);};

export const newsEditorTags = params => { return instance.post(`${base}/news/editTags`, params ).then(res => res.data);};
/* gmc */

/*查询banner接口管理*/
export const queryBanner = params => { return instance.post(`${base}/banner/find`, params).then(res => res.data); };


/*查询订单接口管理*/
/*列表*/
export const getOrderList = params => { return instance.post(`${base}/order/getOrderList`, params).then(res => res.data); };
/*详情*/
export const getOrderDetail = params => { return instance.post(`${base}/order/getOrderByOne`, params).then(res => res.data); };
/*确认/取消,收/发货*/
export const modifyOrder = params => { return instance.post(`${base}/order/modifyOrder`, params).then(res => res.data); };
export const getOrderConfirm = params => { return instance.post(`${base}/order/confirm`, params).then(res => res.data); };
export const getOrderCancel = params => { return instance.post(`${base}/order/cancel`, params).then(res => res.data); };

/*添加anner接口管理*/
export const addBanner = params => { return instance.post(`${base}/banner/add`, params ).then(res => res.data); };
/*编辑banner接口管理*/
export const updateBanner = params => { return instance.post(`${base}/banner/update`, params ).then(res => res.data); };
/*删除banner接口管理*/
export const deleteBanner = params => { return instance.post(`${base}/banner/delete`, params ).then(res => res.data); };

/*查询消息接口管理*/
export const queryMessage = params => { return instance.post(`${base}/message/find`, params).then(res => res.data); };
/*添加消息接口管理*/
export const addMessage = params => { return instance.post(`${base}/message/add`, params ).then(res => res.data); };
///*编辑消息接口管理*/
//export const updateMessage = params => { return instance.post(`${base}/message/update`, params ).then(res => res.data); };
/*删除消息接口管理*/
export const deleteMessage = params => { return instance.post(`${base}/message/delete`, params ).then(res => res.data); };
//export const deleteMessage = params => { return axios.get(`${base}/message/delete`, { params: params }); };

/*查询启动页接口管理*/
export const queryStartup = params => { return instance.post(`${base}/startup/find`, params).then(res => res.data); };
/*添加启动页接口管理*/
export const addStartup = params => { return instance.post(`${base}/startup/add`, params ).then(res => res.data); };
///*编辑消息接口管理*/
//export const updateMessage = params => { return instance.post(`${base}/message/update`, params ).then(res => res.data); };
/*删除启动页接口管理*/
export const deleteStartup = params => { return instance.post(`${base}/startup/delete`, params ).then(res => res.data); };



/*财务管理模块--开始*/

/*1、流水明细列表*/


// 获取流水明细列表接口
export const getWaterList = params => { return instance.post(`${base}/finance/fundList`, params ).then(res => res.data); };



/*2、充值明细列表*/

// 获取充值明细列表接口
export const getRechargeList = params => { return instance.post(`${base}/finance/infundList`, params ).then(res => res.data);};
// 充值面额设置接口
export const denominationSetup = params => { return instance.post(`${base}/finance/denominationSetup`, params ).then(res => res.data);};
// 充值面额列表接口
export const denominationList = params => { return instance.post(`${base}/finance/denominationList`, params ).then(res => res.data);};
// 系统赠送资金接口
export const giveFund = params => { return instance.post(`${base}/finance/giveFund`, params ).then(res => res.data);};
// 系统代扣资金接口
export const reduceFund = params => { return instance.post(`${base}/finance/reduceFund`, params ).then(res => res.data);};


/*3、积分明细列表*/
export const getIntegralhandle = params => { return instance.post(`${base}/finance/integralhandle`, params ).then(res => res.data); };
export const getIntegralList = params => { return instance.post(`${base}/finance/integralList`, params ).then(res => res.data); };
export const getPointsList = params => { return instance.post(`${base}/finance/pointsList`, params ).then(res => res.data); };
// 系统积分设置接口
export const getPointsList11 = params => { return instance.post(`${base}/finance/pointsList`, params ).then(res => res.data); };
// 系统赠送积分接口
export const givePoints = params => { return instance.post(`${base}/finance/givePoints`, params ).then(res => res.data);};
// 系统扣除积分接口
export const reducePoints = params => { return instance.post(`${base}/finance/reducePoints`, params ).then(res => res.data);};

/*4、提现管理列表*/
export const getWithdrawList = params => { return instance.post(`${base}/finance/check`, params ).then(res => res.data);};

export const setWithdraw = params => { return instance.post(`${base}/finance/withdraw`, params ).then(res => res.data);};

export const withImport = params => { return instance.post(`${base}/finance/withImport`, params ).then(res => res.data);};
export const withContent = params => { return instance.post(`${base}/finance/withContent`, params ).then(res => res.data);};
/*5、返利管理列表*/
export const getRebateList = params => { return instance.post(`${base}/rebate/rebateManageList`, params ).then(res => res.data);};
export const setRebate = params => { return instance.post(`${base}/rebate/modifyRebateLimit`, params ).then(res => res.data);};
export const readRebate = params => { return instance.post(`${base}/rebate/rebateLimit`, params ).then(res => res.data);};
export const rebateInfo = params => { return instance.post(`${base}/rebate/rebateUserMsg`, params ).then(res => res.data);};

/*财务管理模块--结束*/




/*权限管理*/
/**获取所有权限*/
export const queryResource = params => { return instance.post(`${base}/resource/queryResource`, params ).then(res => res.data);};
/** 根据id获取点击的用户已有的权限*/
export const queryResourceByRoleId = params => { return instance.post(`${base}/resource/queryResourceByPositionId`, params ).then(res => res.data);};
/**分配权限*/
export const roleUpdate = params => { return instance.post(`${base}/resource/UpdateRoleResourceByRoleId`, params ).then(res => res.data);};
/** 左侧菜单*/
export const leftMenu = params => { return instance.post(`${base}/resource/LeftMenu`, params ).then(res => res.data);};



